/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package booth;

import JavaClass.ActionAll;
import Main.ExpoManagerMain;
import check.check;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author Mai Lan
 */
public class boothAction {
    public static  void loadBooth(JTable tbbooth){
        Vector boothcp=new Vector();
        Vector boothfeil=new Vector();
          boothcp.clear();
            boothcp.add("ID");
            boothcp.add("IDExhibitor");
            boothcp.add("IDZone");
            boothcp.add("NameBooth");
            boothcp.add("DateCreate");
            boothcp.add("NumberStaff");
            boothcp.add("MoneyService");
            boothcp.add("Status");
          boothfeil.add("ID");
          boothfeil.add("IDEX");
          boothfeil.add("IDZone");
          boothfeil.add("NameBooth");
          boothfeil.add("dateCreate");
          boothfeil.add("NumberStaff");
          boothfeil.add("MoneyService");
          boothfeil.add("Status");
          ActionAll.LoadInfor(boothcp, tbbooth, boothfeil, "Booth");

        }
    public static  void insertbooth(JTable tblBoothList,JTextField txtnameBooth,JComboBox cobIdEx,JComboBox cobIDZone,JTextField txtDate,JTextField txtNumstaff,JTextField txtMoney,JTextArea teaStatus){

        
            boolean checkreadyData=check.checkReadlyData("Booth", "NameBooth", txtnameBooth, ExpoManagerMain.conn);
            if(checkreadyData==false){
                return;
            }else{

                try {
                    String sqlInsertBooth = "Insert into Booth (NameBooth,IDEX,IDZone," +
                    "dateCreate,NumberStaff,MoneyService,Status) values(?,?,?,?,?,?,?)";
                    PreparedStatement psm = ExpoManagerMain.conn.prepareStatement(sqlInsertBooth);
                    psm.setString(1, txtnameBooth.getText().trim());
                    psm.setString(2, (String) cobIdEx.getSelectedItem());

                    psm.setString(3, (String)  cobIDZone.getSelectedItem());
                    psm.setString(4, txtDate.getText().trim());
                    psm.setString(5, txtNumstaff.getText().trim());
                    psm.setString(6, txtMoney.getText().trim());
                    psm.setString(7, teaStatus.getText().trim());
                    psm.executeUpdate();
                    boothAction.loadBooth(tblBoothList);
                    cobIDZone.removeAllItems();
                     check.id(cobIDZone, "Zone");

                    cobIdEx.removeAllItems();
                   check.id(cobIdEx, "Exhibitor");


                  
                } catch (SQLException ex) {
                    Logger.getLogger(boothAction.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
     public static  void updateBooth(JTable tblBoothList,JTextField txtnameBooth,JComboBox cobIdEx,JComboBox cobIDZone,JTextField txtDate,JTextField txtNumstaff,JTextField txtMoney,JTextArea teaStatus){

        
        if(tblBoothList.isCellSelected(tblBoothList.getSelectedRow(), tblBoothList.getSelectedColumn())==false){

            JOptionPane.showMessageDialog(null, "Please choice information want to update on list");
            return;
        }else{
            
            try {
                int n=tblBoothList.getSelectedRow();
                String id=(String) tblBoothList.getValueAt(n, 0);
                String sql = "Update Booth set NameBooth='" + txtnameBooth.getText().trim() + "',IDEX=" + (String) cobIdEx.getSelectedItem() + ",IDZone=" + (String) cobIDZone.getSelectedItem() + ",dateCreate='" + txtDate.getText().trim() + "',NumberStaff=" + txtNumstaff.getText().trim() + ",MoneyService='" + txtMoney.getText().trim() + "',Status='" + teaStatus.getText().trim() + "' where ID=" + id;
                Statement st = ExpoManagerMain.conn.createStatement();
                st.executeUpdate(sql);
                cobIDZone.removeAllItems();

                cobIdEx.removeAllItems();
                check.id(cobIDZone, "Zone");
                check.id(cobIdEx, "Exhibitor");

                boothAction.loadBooth(tblBoothList);
                
            } catch (SQLException ex) {
                Logger.getLogger(Booth.class.getName()).log(Level.SEVERE, null, ex);
            }
        
        }


    }
    public static  void DeleBooth(JTable tbboot){
        ActionAll.deleteInfor(tbboot, "Booth", "ID");
        boothAction.loadBooth(tbboot);
       
    }
    
}
